/**
 * Created by forcht on 2018/4/28.
 */
public class Solution {
    public int numDistinct(String S, String T) {
        int s=S.length();
        int t=T.length();
        int[][] dp=new int[t+1][s+1];
        for(int i=0;i<s;i++)dp[0][i]=1;
        for(int i=1;i<=t;i++){
            for(int j=1;j<=s;j++){
                if(S.charAt(j-1)==T.charAt(i-1)){
                    dp[i][j]=dp[i-1][j-1]+dp[i][j-1];
                }else {
                    dp[i][j]=dp[i][j-1];
                }
            }
        }
        return dp[t][s];
    }
}
